<template>
	<view class="ys">
		<view class="no-list" v-if="list.length == 0">
			<image src="/static/index/nolist.png" mode="widthFix"></image>
			- 暂无数据 -
		</view>
		<view class="list" v-else>
			<view class="item" v-for="(item,index) in list" :key="index" @click="clickRoom(item)">
				<view class="title">
					房间号：{{item.name}}
				</view>
				<view :class="item.status.value ==1?'tips':'tips red'">
					{{item.status.text}}
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		getRoom,
		addOrder
	} from "@/api/staff.js"
	export default {
		data() {
			return {
				list: [],
			}
		},
		onLoad() {

		},
		onShow() {
			this.getRoomList()
		},
		methods: {
			clickRoom(item) {
				var that = this
				if (item.status.value == 1) {
					uni.showModal({
						title: '温馨提示',
						content: '确定使用此房间吗?',
						success(res) {
							if (res.confirm) {
								addOrder({
									room_id: item.id
								}).then(res => {
									uni.$showMsg(res.msg)
									if (res.code == 0) {
										that.getRoomList()
									}
								})
							}
						}
					})
				} else {
					uni.navigateTo({
						url: `./detail?id=${item.id}`
					})
				}
			},
			getRoomList() {
				getRoom().then(res => {
					if (res.code == 0) {
						this.list = res.data
					} else {
						uni.$showMsg(res.msg, function() {
							uni.navigateBack()
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.add {
		position: fixed;
		z-index: 1005;
		right: 0;
		bottom: 10%;

		image {
			width: 40px;
			height: 40px;
		}
	}

	.list {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 15px 10px;
		box-sizing: border-box;
		flex-wrap: wrap;

		.item {
			background: #fff;
			border-radius: 6px;
			padding: 10px;
			box-sizing: border-box;
			width: 48%;
			margin-bottom: 15px;
			box-shadow: 0 0 5px #eee;

			.title {
				font-weight: bold;
				font-size: 14px;
				border-bottom: 1px solid #ddd;
				padding-bottom: 10px;
			}

			.tips {
				text-align: center;
				height: 60px;
				line-height: 60px;
				color: #319300;
				font-size: 17px;
				letter-spacing: 1px;
				font-weight: bold;

				&.red {
					color: #cf0000;
				}
			}
		}
	}
</style>